﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Threading;
//using Microsoft.PointOfService;

namespace BACKOFFICE
{
    public partial class StartupScreen : DevExpress.XtraEditors.XtraForm
    {
        public static Thread StartupProcedures;

        public StartupScreen()
        {
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
        }

        private void StartupScreen_Load(object sender, EventArgs e)
        {
            progressPanel1.Description = "";

            StartupProcedures = new Thread(new ThreadStart(Startup1));
            StartupProcedures.Name = "STARTUP THREAD";
            StartupProcedures.Start();
        }

        void Startup1()
        {
            try
            {
               progressPanel1.Caption = "Checking Database Connection";
               Thread.Sleep(250);
               if(DataTableClass.IsServerConnected())
               {
                   progressPanel1.Caption = "Loading Employee Data";
                   Thread.Sleep(250);
                   DataTableClass.LoadDataTable("EmployeeLogin", DataTableClass.EmployeeLogin);
                   Thread.Sleep(250);
                   DataTableClass.LoadDataTable("EmployeeInfo", DataTableClass.EmployeeInfo);
                   Thread.Sleep(250);
                   DataTableClass.LoadDataTable("EmployeeTimeSheet", DataTableClass.EmployeeTimeSheet);
                   Thread.Sleep(250);
                   DataTableClass.LoadDataTable("JobTitles", DataTableClass.JobTitles);
                   Thread.Sleep(250);

                   progressPanel1.Caption = "Loading Menu Items";
                   Thread.Sleep(250);
                   DataTableClass.LoadDataTable("MenuCategory", DataTableClass.MenuItemsCategory);
                   DataTableClass.LoadMenuCategoryDictionary();
                   Thread.Sleep(250);
                   DataTableClass.LoadDataTable("MenuItems", DataTableClass.MenuItems);
                   DataTableClass.LoadMenuItemsDictionary();
                   Thread.Sleep(250);

                   progressPanel1.Caption = "Loading Receipt Data";
                   Thread.Sleep(250);
                   DataTableClass.LoadDataTable("Receipt", DataTableClass.Receipts);
                   Thread.Sleep(250);
                   DataTableClass.LoadDataTable("ReceiptData", DataTableClass.ReceiptsData);
                   Thread.Sleep(250);
                   DataTableClass.LoadDataTable("PaymentTypes", DataTableClass.PaymentTypes);
                   Thread.Sleep(250);


                   progressPanel1.Caption = "Loading Table Chart";
                   Thread.Sleep(250);
                   //MessageBox.Show("DONE");
                   
               }
            }
            catch(Exception E)
            {
                MessageBox.Show(E.Message);
            }
            finally
            {
                this.Close();
            }
        }


    }
}